<?php

if (! defined('SIMPLE_TEST')) {
    define('SIMPLE_TEST', '../simpletest/');
}
require_once(SIMPLE_TEST . 'autorun.php');

require_once '../Sql/DBCristalDAO.php';
require_once '../Sql/conexion.php';
require_once '../Sql/claseDB.php';
require_once '../Exception/CustomException.php';
require_once '../Class/Cristal.php';


class DBCristalDAOTest extends UnitTestCase {

    function DBCristalDAOTest() {
        $this->UnitTestCase();
    }

     public function testgetPrecio() {
        $DBCristalDAOTest = new DBCristalDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_cristal
                            VALUES ('-1', 'Prueba cristal',
                            'Color prueba', '10', '20', '1');");

        $Precio = $DBCristalDAOTest->getPrecio(-1);
        $this->assertEqual($Precio, 20);
        $DBConn->consulta("DELETE FROM costo_cristal
                          WHERE CCR_ID = -1" );

     }

      public function testgetPrecioPorEspesor() {
        $DBCristalDAOTest = new DBCristalDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_cristal
                            VALUES (-1, 'Prueba cristal',
                            'Color prueba', 10, 20, 1)");

        $DBConn->consulta( "INSERT INTO puerta_ventana_cristal
                            VALUES (-1, NULL, NULL, 'Tipo Prueba',
                            10, 1)");


        $PrecioEspesor = $DBCristalDAOTest->getPrecioPorEspesor( -1, -1 );
        $this->assertEqual( 20, $PrecioEspesor['CCR_PRECIO'] );

        $DBConn->consulta("DELETE FROM costo_cristal
                          WHERE CCR_ID = -1" );

        $DBConn->consulta("DELETE FROM puerta_ventana_cristal
                          WHERE PVC_ID = -1" );

      }

       public function testgetColor() {
        $DBCristalDAOTest = new DBCristalDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_cristal
                            VALUES ('-1', 'Prueba cristal',
                            'Color prueba', '10', '20', '1')");

        $Color = $DBCristalDAOTest->getColor(-1);
        $this->assertEqual( $Color,'Color prueba' );
        $DBConn->consulta("DELETE FROM costo_cristal
                          WHERE CCR_ID = -1" );

       }

        public function testgetNombre() {
        $DBCristalDAOTest = new DBCristalDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_cristal
                            VALUES ('-1', 'Prueba cristal',
                            'Color prueba', '10', '20', '1')");

        $Nombre = $DBCristalDAOTest->getNombre(-1);
        $this->assertEqual( $Nombre,'Prueba cristal' );
        $DBConn->consulta("DELETE FROM costo_cristal
                          WHERE CCR_ID = -1" );

       }

        public function testgetEspesor() {
        $DBCristalDAOTest = new DBCristalDAO();
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO costo_cristal
                            VALUES ('-1', 'Prueba cristal',
                            'Color prueba', 10, 20, 1)");

        $Espesor = $DBCristalDAOTest->getEspesor( -1 );
        $this->assertEqual( $Espesor, 10 );
        $DBConn->consulta("DELETE FROM costo_cristal
                          WHERE CCR_ID = -1" );

       }

       public function testsetCristal() {
        $DBCristalDAOTest = new DBCristalDAO();
        $miCristal = new Cristal('Prueba cristal', 10, 20, 30, 40, 50, 2);
        $DBConn = null;
        $conexion = new conexion();
        $DBConn = $conexion->setConnect();
        $DBConn->consulta( "INSERT INTO presupuesto
                           VALUES (-1, 'PRESUPUESTO',
                           '2010-06-04', NULL, NULL,
                           NULL, 1, 1)" );


        $DBCristalDAOTest->setCristal( $miCristal, -1 );
        $DBConn->consulta( "SELECT * FROM Cristal
                        WHERE CRT_NOMBRE = 'Prueba cristal'
                        AND CRT_COLOR = 10
                        AND CRT_ESPESOR = 20
                        AND CRT_ANCHO = 30
                        AND CRT_ALTO = 40
                        AND CRT_PRECIO = 50
                        AND CRT_CANTIDAD = 2
                        AND CRT_STATUS = 1
                        ORDER BY CRT_ID DESC " );

        $fila = $DBConn->extraer_registro();
        $id = $fila['CRT_ID'];
        $this->assertEqual( $fila['CRT_NOMBRE'], 'Prueba cristal' );
        $this->assertEqual( $fila['CRT_COLOR'], 10 );
        $this->assertEqual( $fila['CRT_ESPESOR'], 20 );
        $this->assertEqual( $fila['CRT_ANCHO'], 30 );
        $this->assertEqual( $fila['CRT_ALTO'], 40 );
        $this->assertEqual( $fila['CRT_PRECIO'], 50 );
        $this->assertEqual( $fila['CRT_CANTIDAD'], 2 );

        $DBConn->consulta( "SELECT *
                            FROM detalle_presupuesto
                            WHERE DPR_PTO_ID = -1" );

        $fila = $DBConn->extraer_registro();
        $this->assertEqual( $fila['DPR_PTO_ID'], -1 );
        $this->assertEqual( $fila['DPR_CRT_ID'], $id );
        $DBConn->consulta( "DELETE FROM detalle_presupuesto
                            WHERE DPR_CRT_ID = $id
                            AND DPR_PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM presupuesto
                            WHERE PTO_ID = -1" );

        $DBConn->consulta( "DELETE FROM cristal
                            WHERE CRT_ID = $id" );

    }
}
?>
